package com.insurance.listener;

import org.apache.activemq.ActiveMQConnectionFactory;

import javax.jms.*;

/**
 * Created with IntelliJ IDEA.
 * User: 朱雄
 * Date: 2020/11/03 14:02
 * Description:
 * Version: V1.0
 */
public class ConsumerMessageListener {
    private static final String URL = "tcp://106.14.247.137:61616";
    //队列的名字
    private static final String QUEUENAME = "queue-test";

    public static void main(String[] args) throws JMSException {
        //1 、创建ConnectionFatory工厂
        ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(URL);
        //2、创建Connection连接
        Connection connection = connectionFactory.createConnection();
        //3、启动连接
        connection.start();
        //4、创建会话 : 不设置事务 自动应答模式
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        //5、创建目标
        Destination destination = session.createQueue(QUEUENAME);
        //6、创建一个生产者
        MessageProducer messagerProducer = session.createProducer(destination);
        for (int i = 0; i < 50; i++) {
            //7、创建消息
            TextMessage textMessage = session.createTextMessage("消息" + i);
            //8、发送消息
            messagerProducer.send(textMessage);
            System.out.println("发送的消息==" + textMessage);
        }
    }
    }
